<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>打开一个持久的 PostgreSQL 连接</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.pg-pconnect" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">pg_pconnect</h1>
    <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">pg_pconnect</span> &mdash; <span class="dc-title">打开一个持久的 PostgreSQL 连接</span></p>

   </div>
 
 <div class="refsect1 description" id="refsect1-function.pg-pconnect-description">
  <h3 class="title">说明</h3>
    <div class="methodsynopsis dc-description">
     <span class="methodname"><strong>pg_pconnect</strong></span> 
      ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$connection_string</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$connect_type</code></span>
    ] ) : <span class="type">resource</span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>pg_pconnect()</strong></span> 打开一个到 PostgreSQL 数据库的持久连接。返回其它 PostgreSQL 函数所需要的连接资源号。
    </p>
    <p class="para">
   If a second call is made to <span class="function"><strong>pg_pconnect()</strong></span> with
   the same <code class="parameter">connection_string</code> as an existing connection, the
   existing connection will be returned unless you pass
   <strong><code>PGSQL_CONNECT_FORCE_NEW</code></strong> as
   <code class="parameter">connect_type</code>.
  </p>
    <p class="para">
     要打开持久连接功能，<var class="filename">php.ini</var> 中的 <a href="pgsql.configuration.html#ini.pgsql.allow-persistent" class="link">pgsql.allow_persistent</a> 参数必须为 &quot;On&quot;（也是默认值）。
最大持久连接数目由 <var class="filename">php.ini</var> 中的 <a href="pgsql.configuration.html#ini.pgsql.max-persistent" class="link">pgsql.max_persistent</a>
参数定义（默认为 -1 表示没有限制）。所有连接的数目可由 <var class="filename">php.ini</var> 中的 <a href="pgsql.configuration.html#ini.pgsql.max-links" class="link">pgsql.max_links</a> 参数设置。
    </p>
    <p class="para">
     <span class="function"><a href="pg_close.html" class="function">pg_close()</a></span> 不能关闭由 <span class="function"><strong>pg_pconnect()</strong></span> 打开的持久连接。
    </p>
   </div>


 <div class="refsect1 parameters" id="refsect1-function.pg-pconnect-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">connection_string</code></dt>

     <dd>

      <p class="para">
       The <code class="parameter">connection_string</code> can be empty to use all default parameters, or it 
       can contain one or more parameter settings separated by whitespace. 
       Each parameter setting is in the form <em>keyword = value</em>. Spaces around 
       the equal sign are optional. To write an empty value or a value 
       containing spaces, surround it with single quotes, e.g., <em>keyword = 
       &#039;a value&#039;</em>. Single quotes and backslashes within the value must be 
       escaped with a backslash, i.e., \&#039; and \.  
      </p>
      <p class="para">
       The currently recognized parameter keywords are:
       <code class="parameter">host</code>, <code class="parameter">hostaddr</code>, <code class="parameter">port</code>,
       <code class="parameter">dbname</code>, <code class="parameter">user</code>,
       <code class="parameter">password</code>, <code class="parameter">connect_timeout</code>,
       <code class="parameter">options</code>, <code class="parameter">tty</code> (ignored), <code class="parameter">sslmode</code>,
       <code class="parameter">requiressl</code> (deprecated in favor of <code class="parameter">sslmode</code>), and
       <code class="parameter">service</code>.  Which of these arguments exist depends
       on your PostgreSQL version.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">connect_type</code></dt>

     <dd>

      <p class="para">
       If <strong><code>PGSQL_CONNECT_FORCE_NEW</code></strong> is passed, then a new connection
       is created, even if the <code class="parameter">connection_string</code> is identical to
       an existing connection.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-pconnect-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   PostgreSQL connection resource on success, <strong><code>FALSE</code></strong> on failure.
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.pg-pconnect-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2508">
    <p><strong>Example #1 Using <span class="function"><strong>pg_pconnect()</strong></span></strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$dbconn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_pconnect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=mary"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//connect&nbsp;to&nbsp;a&nbsp;database&nbsp;named&nbsp;"mary"<br /><br /></span><span style="color: #0000BB">$dbconn2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_pconnect</span><span style="color: #007700">(</span><span style="color: #DD0000">"host=localhost&nbsp;port=5432&nbsp;dbname=mary"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//&nbsp;connect&nbsp;to&nbsp;a&nbsp;database&nbsp;named&nbsp;"mary"&nbsp;on&nbsp;"localhost"&nbsp;at&nbsp;port&nbsp;"5432"<br /><br /></span><span style="color: #0000BB">$dbconn3&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_pconnect</span><span style="color: #007700">(</span><span style="color: #DD0000">"host=sheep&nbsp;port=5432&nbsp;dbname=mary&nbsp;user=lamb&nbsp;password=foo"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//connect&nbsp;to&nbsp;a&nbsp;database&nbsp;named&nbsp;"mary"&nbsp;on&nbsp;the&nbsp;host&nbsp;"sheep"&nbsp;with&nbsp;a&nbsp;username&nbsp;and&nbsp;password<br /><br /></span><span style="color: #0000BB">$conn_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"host=sheep&nbsp;port=5432&nbsp;dbname=test&nbsp;user=lamb&nbsp;password=bar"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$dbconn4&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_pconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn_string</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">//connect&nbsp;to&nbsp;a&nbsp;database&nbsp;named&nbsp;"test"&nbsp;on&nbsp;the&nbsp;host&nbsp;"sheep"&nbsp;with&nbsp;a&nbsp;username&nbsp;and&nbsp;password<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.pg-pconnect-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="pg_connect.html" class="function" rel="rdfs-seeAlso">pg_connect()</a> - 打开一个 PostgreSQL 连接</span></li>
    <li class="member">
     <a href="features.persistent_connections.html" class="link">持久数据库连接</a>
    </li>
   </ul>
  </p>
 </div>

  </div></div></div></body></html>